package com.tzy.for10evalue.haoyong.excelexport.sysbackservice.impl;

import com.aebiz.b2b2ccorecommon.b2b.dto.product.common.ProductConstrant;
import com.aebiz.b2b2ccorecommon.utils.ApiParamDTO;
import com.aebiz.baseframework4ms.exception.AppException;
import com.aebiz.deli.common2.constants.ImportExcelConstants;
import com.aebiz.deli.common2.product.excel.CommonImportDetailDTO;
import com.aebiz.pcweb.product.productinfo.service.AbstractImportService;
import com.aebiz.plugins.b2b.common.dto.product.productunit.plugins.productunit_p2.params.ProductUnitExcelDTO;
import com.alibaba.fastjson.JSON;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("productUnitImportService")
public class ProductUnitImportServiceImpl extends AbstractImportService<ProductUnitExcelDTO> {
    @Override
    protected void checkNotNullParam(List<ProductUnitExcelDTO> importProductUnitExcels) {
        if (CollectionUtils.isEmpty(importProductUnitExcels)) {
            throw new AppException("excel为空！");
        }
    }

    @Override
    protected Integer getImportType() {
        return ImportExcelConstants.PRODUCT_UNIT_IMPORT;//对前端提供的导入类型 便于查看日志主表
    }

    @Override
    protected void sendWithoutTransactionMsg(List<ProductUnitExcelDTO> importProductUnitExcels, String logName, ApiParamDTO apiParamDTO) {
        int i=1;
        for(ProductUnitExcelDTO dto:importProductUnitExcels){
            dto.setLineId(i);
            dto.setApiParamDTO(apiParamDTO);
            dto.setExcelName(logName);
            CommonImportDetailDTO commonDto = new CommonImportDetailDTO();
            commonDto.setType(5);//同一个topic内部转发的的导入类型
            commonDto.setMessage(JSON.toJSONString(dto));
            //消息发送完 至此导入操作结束 根据topic名称去消息消费服务
            syncMessageService.sendWithoutTransaction(ProductConstrant.PRODUCT_BATCH_IMPORT_NEW, JSON.toJSONString(commonDto));
            i++;
        }
    }

}
